#!/bin/bash
# 统计每个平台截止到指定时间最新的已开区服id
script_path=/data/script/cqby-count
range_file=${script_path}/nameRange.ini
create_file=${script_path}/needCreatePlatform.ini
qufu_file=/data/.slogin.profile


getRange(){
    awk -v name=$1 '{if($1==name)print $3":"$4":"$6}' ${range_file}
}

getOneLatest(){
    info=`getRange $1`
    #echo $info
    if [ -z $info ];then
        echo "$1 平台不存在"
    else
        platform=`echo $info | awk -F: '{print $1}'`
        beginid=`echo $info | awk -F: '{print $2}'`
        endid=`echo $info | awk -F: '{print $3}'`
        endtime=$2
        echo "$1:`awk -F, -v be=$beginid -v en=$endid -v platform=$platform -v endtime=$endtime '{if($NF==1 && $1==platform && $2>=be && $2<=en && $5<=endtime)print $1,$2}' $qufu_file | sort -t ' ' -k 2 -n |  t
ail -1`"
    fi
}

getAllLatest(){
    for line in `cat ${create_file} | awk '{print $1}'`;do
        getOneLatest $line $1
    done
}

case $# in
2)
    # cd /data;./create_list_cqby
    [ $1 == "all" ] && getAllLatest $2 || getOneLatest $1 $2
    ;;
*)
    echo "usage:`basename $0` 平台名称/all '年-月-日 时:分:秒'"
    ;;
esac